<?php
/**
 * 初始化安装数据
 */

// 不选择安装数据时不执行sql文件
if (isset($_GET['is_install_db']) && $_GET['is_install_db']) {
    if (is_file(APPSPATH.'Module/Config/App.php')) {
        $rt = \Phpcmf\Service::M('app')->install('module');
        if ($rt['code']) {
            \Phpcmf\Service::M('module', 'module')->install('news', null, 0, 1);
            $sql = file_get_contents(MYPATH.'Config/demo.sql');
            if ($sql) {
                $sql = str_replace('{dbprefix}', \Phpcmf\Service::M()->prefix, $sql);
                \Phpcmf\Service::M()->query_all($sql);
            }
        }
    }
}
//标签调用
if (is_file(APPSPATH.'Mbdy/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('mbdy');
}
//补丁
if (is_file(APPSPATH.'Buding/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('buding');
}
//官网
if (is_file(APPSPATH.'W/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('w');
}
//20帮助
if (is_file(APPSPATH.'Bang/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('bang');
}
//19 导航
if (is_file(APPSPATH.'Daohang/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('daohang');
}
//Dever工具
if (is_file(APPSPATH.'Dever/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('dever');
}
//Member 会员
if (is_file(APPSPATH.'Member/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('member');
}
//4Pay 支付
if (is_file(APPSPATH.'Pay/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('pay');
}
//5积分 scorelog
if (is_file(APPSPATH.'Scorelog/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('scorelog');
}
//6会员 / huiyuan huiyuan
if (is_file(APPSPATH.'Huiyuan/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('huiyuan');
}
//7评论 / comment
if (is_file(APPSPATH.'Comment/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('comment');
}
//8 内容收藏 / favorite
if (is_file(APPSPATH.'Favorite/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('favorite');
}
//9 表单 / mform
if (is_file(APPSPATH.'Mform/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('mform');
}
//10 圈子 / quan
if (is_file(APPSPATH.'Quan/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('quan');
}
//11 通知 / notice
if (is_file(APPSPATH.'Notice/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('notice');
}
//12 点赞 / zan
if (is_file(APPSPATH.'Zan/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('zan');
}
//14 转移主表 / usu_fbzzb
if (is_file(APPSPATH.'Usu_fbzzb/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('usu_fbzzb');
}
//16 服务 / fuwu
if (is_file(APPSPATH.'Fuwu/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('fuwu');
}
//18 经验值 / explog
if (is_file(APPSPATH.'Explog/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('explog');
}
//21 反馈 / fankui
if (is_file(APPSPATH.'Fankui/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('fankui');
}
//22 建议 / jianyi
if (is_file(APPSPATH.'Jianyi/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('jianyi');
}
//23 举报 / jubao
if (is_file(APPSPATH.'Jubao/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('jubao');
}
//24 开关 / fstatus
if (is_file(APPSPATH.'Fstatus/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('fstatus');
}
//25 海报 / haibao
if (is_file(APPSPATH.'Haibao/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('haibao');
}
//26 图标 / tubiao
if (is_file(APPSPATH.'Tubiao/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('tubiao');
}
//27 热门 / remen
if (is_file(APPSPATH.'Remen/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('remen');
}
//36 微信 / weixin
if (is_file(APPSPATH.'Weixin/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('weixin');
}
//41 百度编辑器 / ueditor
if (is_file(APPSPATH.'Ueditor/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('ueditor');
}
// 60 消息通知 / duixin
if (is_file(APPSPATH.'Duixin/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('duixin');
}
// 圈帖属性
if (is_file(APPSPATH.'Quantieshuxing/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('quantieshuxing');
}
// 安装 模板
if (is_file(APPSPATH.'Qingchun/Config/App.php')) {
    \Phpcmf\Service::M('app')->install('qingchun');
}
// 默认站点信息字段
$site_field = [];
$site_field[] = '{"name":"二维码","fieldname":"erweima","fieldtype":"Ftable","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"is_add":"1","is_first_hang":"0","count":"","first_cname":"","hang":{"1":{"name":""},"2":{"name":""},"3":{"name":""},"4":{"name":""},"5":{"name":""}},"field":{"1":{"type":"3","name":"图片","width":"200","option":""},"2":{"type":"1","name":"名称","width":"200","option":""},"3":{"type":"1","name":"跳转地址","width":"","option":""},"4":{"type":"0","name":"","width":"","option":""},"5":{"type":"0","name":"","width":"","option":""},"6":{"type":"0","name":"","width":"","option":""},"7":{"type":"0","name":"","width":"","option":""},"8":{"type":"0","name":"","width":"","option":""},"9":{"type":"0","name":"","width":"","option":""},"10":{"type":"0","name":"","width":"","option":""}},"width":"","height":"","css":""},"validate":{"required":"0","pattern":"","errortips":"","xss":"1","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';
$site_field[] = '{"name":"友情链接","fieldname":"youqing","fieldtype":"Ftable","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"is_add":"1","is_first_hang":"0","count":"","first_cname":"","hang":{"1":{"name":""},"2":{"name":""},"3":{"name":""},"4":{"name":""},"5":{"name":""}},"field":{"1":{"type":"3","name":"图片","width":"200","option":""},"2":{"type":"1","name":"名称","width":"200","option":""},"3":{"type":"1","name":"跳转地址","width":"","option":""},"4":{"type":"0","name":"","width":"","option":""},"5":{"type":"0","name":"","width":"","option":""},"6":{"type":"0","name":"","width":"","option":""},"7":{"type":"0","name":"","width":"","option":""},"8":{"type":"0","name":"","width":"","option":""},"9":{"type":"0","name":"","width":"","option":""},"10":{"type":"0","name":"","width":"","option":""}},"width":"","height":"","css":""},"validate":{"required":"0","pattern":"","errortips":"","xss":"1","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';
$site_field[] = '{"name":"分享图","fieldname":"fenxiangtu","fieldtype":"File","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"fieldtype":"VARCHAR","fieldlength":"255","ext":"jpg,gif,png","size":"10","attachment":"0","image_reduce":"500","is_ext_tips":"0","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';
$site_field[] = '{"name":"用户协议","fieldname":"yonghuxieyi","fieldtype":"Ueditor","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"enter":"0","down_img":"0","watermark":"0","show_bottom_boot":"0","autofloat":"0","remove_style":"0","div2p":"0","autoheight":"0","page":"0","mode":"1","tool":"bold, italic,underline","mode2":"2","tool2":"bold, italic, underline","mode3":"2","tool3":"bold, italic, underline","attachment":"0","image_endstr":"","value":"","width":"100%","height":"300","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';
$site_field[] = '{"name":"顶部导航颜色","fieldname":"dbdhys","fieldtype":"Color","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"field":"","value":"","width":"","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';
$site_field[] = '{"name":"顶部文字颜色","fieldname":"dbwzys","fieldtype":"Color","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"field":"","value":"","width":"","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';
$site_field[] = '{"name":"小程序登陆开关","fieldname":"xcxdlkg","fieldtype":"Radio","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"options":"开启|0\r\n关闭|1","is_field_ld":"0","value":"0","fieldtype":"","fieldlength":"","show_type":"0","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}';

foreach ($site_field as $t) {
    $value = dr_string2array($t);
    if (!$value) {
        continue;
    }
    $field = \Phpcmf\Service::L('field')->get($value['fieldtype']);
    $value['setting'] = dr_string2array($value['setting']);
    \Phpcmf\Service::M('Field')->relatedid = 1;
    \Phpcmf\Service::M('Field')->relatedname = 'site';
    \Phpcmf\Service::M('Field')->add($value, $field);
}